import java.util.ArrayList;
import java.util.List;

public class 找到字符串中所有字母异位词 {

    public List<Integer> findAnagrams(String ss, String pp) {
        List<Integer> ans = new ArrayList<>();
        char[] s = ss.toCharArray();
        char[] p = pp.toCharArray();
        int[] hash = new int[256]; // hash 记录
        for (char ch : p) hash[ch]--;
        int l = 0;
        int count = 0;
        for (int r = 0; r < s.length; r++) {
            if (hash[s[r]]++ < 0) {
                count++;
            }
            if (p.length == r - l + 1 ) {
                if (p.length == count) {
                    ans.add(l);
                }
                if (hash[s[l++]]-- <= 0) {
                    count--;
                }
            }

        }
        return ans;
    }


}
